<?php
require_once '../include/common.inc.php';

$sql = "select * FROM  pro_product order by id desc ";
$query = $db->query($sql);
while($rs=$db->fetch_array($query))
{
	$r[]=$rs;
}



header("Content-type:application/vnd.ms-excel");  
header("Content-Disposition:filename=Product_Info_" . date("Ymd") . ".xls");  

echo "Code\t";  
echo "Product Name (Danish)\t";
echo "Product Name (English)\t";
echo "Product Name (Chinese)\t";
echo "Short Description (Danish)\t";
echo "Short Description (English)\t";
echo "Short Description (Chinese)\t";
echo "Long Description (Danish)\t";
echo "Long Description (English)\t";
echo "Long Description (Chinese)\t";
echo "Type\t"; 
echo "Category\t"; 
echo "Publisher\t"; 
echo "Author\t"; 
echo "Supplier\t"; 
echo "Weight (g)\t"; 
echo "Cost\t"; 
echo "Sales Price\t"; 
echo "Stock Status\t"; 
echo "Stock Data\t"; 
echo "Best Seller\t"; 
echo "Is Featured\t";
echo "Is Special\t";
echo "Comments\t\n"; 

for ($i=0;$i<count($r);$i++){

$sql = "select * from pro_type where id in(select type_id FROM  pro_product_type  where product_id=".$r[$i]['id'].")";
$query = $db->query($sql);
while($rs=$db->fetch_array($query))
{
	$r[$i]['type'].=$rs['name']."/";
}

$sql = "select * from pro_category where id in(select category_id FROM  pro_product_category  where product_id=".$r[$i]['id'].")";
$query = $db->query($sql);
while($rs=$db->fetch_array($query))
{
	$r[$i]['category'].=$rs['name']."/";
}

$sql = "select * from pro_publisher where id=".$r[$i]['publiser_id'];
$query = $db->query($sql);
while($rs=$db->fetch_array($query))
{
	$r[$i]['publisher'].=$rs['name'];
}

$sql = "select * from pro_publisher where id=".$r[$i]['publiser_id'];
$query = $db->query($sql);
while($rs=$db->fetch_array($query))
{
	$r[$i]['publisher'].=$rs['name'];
}

$sql = "select * from pro_author where id=".$r[$i]['author_id'];
$query = $db->query($sql);
while($rs=$db->fetch_array($query))
{
	$r[$i]['author'].=$rs['name'];
}

$sql = "select * from pro_supplier where id=".$r[$i]['supplier_id'];
$query = $db->query($sql);
while($rs=$db->fetch_array($query))
{
	$r[$i]['supplier'].=$rs['name'];
}

echo replaceHtmlAndJs($r[$i]['code']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['name_d']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['name']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['name_c']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['short_desc_d']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['short_desc']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['short_desc_c']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['long_desc_d']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['long_desc']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['long_desc_c']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['type']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['category']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['publisher']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['author']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['supplier']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['weight']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['cost']  ). "\t"; 
echo replaceHtmlAndJs($r[$i]['price']  ). "\t"; 
if ($r[$i]['stock_status']=="1") echo "yes\t"; else echo "no\t";
echo replaceHtmlAndJs($r[$i]['stock_data']  ). "\t";
if ($r[$i]['is_best']=="1") echo "yes\t"; else echo "no\t";
if ($r[$i]['is_featured']=="1") echo "yes\t"; else echo "no\t";
if ($r[$i]['is_special']=="1") echo "yes\t"; else echo "no\t";
echo replaceHtmlAndJs($r[$i]['comments']  ). "\t\n"; 
}

echo "\n"; 

?>


